package com.superquan.selfstudybootmybatis.utils.proxy.dynamic_proxy_jdk;

import java.lang.reflect.Proxy;

/**
 * @program: self-study-bootmybatis
 * @ClassName AgencyJdkTest
 * @description: jdk动态代理测试类
 * @author: zwq
 **/
public class JdkProxyTest {
    public static void main(String[] args) {
        //被代理对象
        UserDao userDaoImpl = new UserDaoImpl();
        InvocationHandlerImpl invocationHandlerImpl = new InvocationHandlerImpl(userDaoImpl);

        //类加载器
        ClassLoader loader = userDaoImpl.getClass().getClassLoader();
        Class<?>[] interfaces = userDaoImpl.getClass().getInterfaces();

        //主要装载器、一组接口及调用处理动态代理实例
        UserDao newProxyInstance  = (UserDao)Proxy.newProxyInstance(loader, interfaces, invocationHandlerImpl);
        newProxyInstance.save();
    }
}
